// 0 引入 用来发送请求的 方法 一定要把路径补全
import { request } from "../../request/index.js";
Page({
  data: {
    // 轮播图数组
    swiperList: [
      {
        "goodsId": 363,
        "imageSrc": "https://img10.360buyimg.com//babel/jfs/t1/130887/27/22746/83669/621de1c6Ecc97faf2/7d23effd1f2e7793.png",
        "navigatorUrl": "/api/public/v1/goods/detail?goodsId=129",
        "openType": "navigate"
      },
      {
        "goodsId": 723,
        "imageSrc": "https://img10.360buyimg.com//babel/jfs/t1/128119/37/20561/245804/621dc1faE4ffb83c8/729a740aa2d587fd.png",
        "navigatorUrl": "/api/public/v1/goods/detail?goodsId=395",
        "openType": "navigate"
      },
      {
        "goodsId": 731,
        "imageSrc": "https://img11.360buyimg.com//babel/jfs/t1/166892/3/26147/78015/621c8514E677e217e/c1486d82f8755722.png",
        "navigatorUrl": "/api/public/v1/goods/detail?goodsId=38",
        "openType": "navigate"
      }
    ],
    // 导航 数组
    catesList: [
      { "imageSrc": "/icons/3C.png", "name": "数码电器", "navigatorUrl": "/pages/category/main", "openType": "switchtab" },
      { "imageSrc": "/icons/book.png", "name": "邮币", "navigatorUrl": "", "openType": "" },
      { "imageSrc": "/icons/car.png", "name": "汽车生活", "navigatorUrl": "", "openType": "" },
      { "imageSrc": "/icons/clothes.png", "name": "西瓜服饰", "navigatorUrl": "", "openType": "" },
      { "imageSrc": "/icons/dollar.png", "name": "礼品", "navigatorUrl": "", "openType": "" },
      { "imageSrc": "/icons/hour.png", "name": "电脑办公", "navigatorUrl": "", "openType": "" },
      { "imageSrc": "/icons/king.png", "name": "珠宝首饰", "navigatorUrl": "", "openType": "" },
      { "imageSrc": "/icons/phone.png", "name": "搞机达人", "navigatorUrl": "", "openType": "" },
      { "imageSrc": "/icons/shop.png", "name": "居家生活", "navigatorUrl": "", "openType": "" },
      { "imageSrc": "/icons/shuiguo.png", "name": "西瓜生鲜", "navigatorUrl": "", "openType": "" },
    ],
    // 楼层数据
    floorList: [
      {
        "imageSrc": "https://api-hmugo-web.itheima.net/pyg/pic_floor01_title.png",
        "list": [
          {
            "imageSrc": "https://h2.appsimg.com/a.appsimg.com/upload/brand/upcb/2021/11/02/153/ias_caf99710d4d411afea09911c06c8b475_1135x545_85.jpg",
            "imageWidth": 233,
            "name": "怦然心动",
            "navigatorUrl": "/pages/goods_detail/index?goodsId=26018",
            "openType": "navigate"
          }
        ],
        "name": "时尚女装"
      },
      {
        "imageSrc": "https://api-hmugo-web.itheima.net/pyg/pic_floor02_title.png",
        "list": [
          {
            "imageSrc": "https://h2.appsimg.com/a.appsimg.com/upload/brand/upcb/2022/03/01/90/ias_359b816a223d6d9d69854f6c5ba425c5_1135x545_85.jpg",
            "imageWidth": 273,
            "name": "puma",
            "navigatorUrl": "/pages/goods_detail/index?goodsId=3452",
            "openType": "navigate"
          }
        ],
        "name": "户外运动"
      },
      {
        "imageSrc": "https://api-hmugo-web.itheima.net/pyg/pic_floor03_title.png",
        "list": [
          {
            "imageSrc": "https://h2.appsimg.com/a.appsimg.com/upload/brand/upcb/2022/03/08/15/ias_e9e16c389fa72083ba9ec9c06877dd60_1135x545_85.jpg",
            "imageWidth": 273,
            "name": "箱包配饰",
            "navigatorUrl": "/pages/goods_list/index?cid=907",
            "openType": "navigate"
          }
        ],
        "name": "箱包配饰"
      }
    ]
  },
  // 页面开始加载 就会触发
  onLoad: function (options) {
    // wx.clearStorage();
    // 1 发送异步请求获取轮播图数据  优化的手段可以通过es6的 promise来解决这个问题 
    // wx.request({
    //   url: 'https://api.zbztb.cn/api/public/v1/home/swiperdata',
    //   success: (result) => {
    //     this.setData({
    //       swiperList: result.data.message
    //     })
    //   }
    // });

    // this.getSwiperList();
    // this.getCateList();
    // this.getFloorList();

  },
  /**
  * 生命周期函数--监听页面显示
  */
  onShow: function () {
    var that = this;

    that.setData({
      statusbarobj: {
        isshowbtn: true,//是否显示按钮
        isshowpre: true, //返回按钮
        isshowhome: true, //首页按钮
        title: "首页标题", //标题
      }
    })
  },
  prechangeopt: function () {
    console.log("组件回调，返回上一页");
  },
  homechangeopt: function () {
    console.log("组件回调，返回首页");
  },

  // 获取轮播图数据
  // getSwiperList() {
  //   request({ url: "/home/swiperdata" })
  //     .then(result => {
  //       console.log('result', result);
  //       this.setData({
  //         swiperList: {
  //           "data": [
  //             {
  //               "goodsId": 129,
  //               "imageSrc": "https://img10.360buyimg.com//babel/jfs/t1/130887/27/22746/83669/621de1c6Ecc97faf2/7d23effd1f2e7793.png",
  //               "navigatorUrl": "/api/public/v1/goods/detail?goodsId=129",
  //               "openType": "navigate"
  //             },
  //             {
  //               "goodsId": 395,
  //               "imageSrc": "https://img10.360buyimg.com//babel/jfs/t1/128119/37/20561/245804/621dc1faE4ffb83c8/729a740aa2d587fd.png",
  //               "navigatorUrl": "/api/public/v1/goods/detail?goodsId=395",
  //               "openType": "navigate"
  //             },
  //             {
  //               "goodsId": 38,
  //               "imageSrc": "https://img11.360buyimg.com//babel/jfs/t1/166892/3/26147/78015/621c8514E677e217e/c1486d82f8755722.png",
  //               "navigatorUrl": "/api/public/v1/goods/detail?goodsId=38",
  //               "openType": "navigate"
  //             }
  //           ],
  //           "message": "OK",
  //           "more": false,
  //           "status": 200
  //         }
  //       })
  //     })
  // },
  // 获取 分类导航数据
  getCateList() {
    request({ url: "/v1/home/catitems" })
      .then(result => {
        this.setData({
          catesList: result
        })
      })
  },
  // 获取 楼层数据
  getFloorList() {
    request({ url: "/v1/home/floordata" })
      .then(result => {
        this.setData({
          floorList: result
        })
      })
  },
})
